package com.kpx.app.broadcast;

import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.support.v4.content.WakefulBroadcastReceiver;

import com.kpx.app.bean.NetworkChangeEvent;
import com.orhanobut.logger.Logger;
import com.kpx.app.utils.systemutils.SystemUtil;

import org.greenrobot.eventbus.EventBus;

public class NetworkChangeReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        NetworkInfo.State state = SystemUtil.getConnectivityStatus(context);
        NetworkChangeEvent e = new NetworkChangeEvent();
        if (state == NetworkInfo.State.DISCONNECTED) {
            e.setStatus(NetworkChangeEvent.DISCONNECTED);
        }
        if (state == NetworkInfo.State.CONNECTED) {
            e.setStatus(NetworkChangeEvent.CONNECTED);
        }
        EventBus.getDefault().post(e);
    }
}
